/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package envasesdeleste.persistencia.broker;

import envasesdeleste.dom.Articulo;
import envasesdeleste.dom.IPersistente;
import envasesdeleste.persistencia.Broker;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 *
 * @author MAT
 */
public class BrokerArticulosAccess extends Broker{
    
    public BrokerArticulosAccess(Articulo objA) {
        super(objA);
  }

    @Override
    public String getInsertCommand() {
        Articulo art =(Articulo)this.getObjP();
        return "INSERT INTO ARTICULOS(Codigo, Descripcio, PrecioCosto, PrecioVenta, Categoria, Stock)" + "VALUES(" + art.getCod() + ",'" + art.getDescripcion()
                + "'," + art.getPrecioCosto() + "," + art.getPrecioVenta() + "," + art.getCategoria().getCod() + "," + art.getStock() + ")";
        
    }

    @Override
    public String getUpdateCommand() {
         Articulo art =(Articulo)this.getObjP();
         return "UPDATE ARTICULOS SET aDescripcio='" + art.getaDescripcion() + "',aTalle='"+art.getaTalle()+"',objCategoria="+art.getObjCategoria().getcNumero()
                    +",aColor='"+art.getaColor()+"',aStock="+art.getaStock()+",aPrecio="+art.getaPrecio()+" WHERE aCodigo='" +art.getaCodigo()+"'";
            
    }

    @Override
    public String getDeleteCommand() {
         Articulo art =(Articulo)this.getObjP();
         return "DELETE FROM ARTICULOS " + " WHERE aCodigo='" +art.getCod()+"'";
    }

    @Override
    public String getSelectCommand() {
        return "SELECT * FROM ARTICULOS";
    }

    @Override
    public void obtenerDesdeResultSet(ResultSet rs, Object IPersistentej) {
        try {
                Articulo art=(Articulo)IPersistentej;
		art.setCod(rs.getInt("Codigo"));
                art.setDescripcion(rs.getString("Descripcion"));
                art.setPrecioCosto(rs.getDouble("PrecioCosto"));
                art.setPrecioVenta(rs.getDouble("PrecioVenta"));
//                art.setCategoria(GestCategorias.get);
                art.setStock(rs.getInt("Stock"));
                } catch (SQLException e) {
			System.out.println("ERROR AL OBTENER LOS ARTICULOS" + " " + e.getMessage());
		}
    }

    @Override
    public IPersistente getNuevo() {
        return new Articulo();
    }

    @Override
    public String getSelectCommand(int numfactura) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
}
